/*==============================================

 * js公共库 用于自定义
 * Copyright 2016 xb, Inc. Author WANGHAO 
 * Licensed xiaomingTECH
 */



/*页面控制*/
;(function ($) {
    /*
    *页面导航控制
    */
    $(document).ready(function(){

        var header = $('.header');
        var header_Height = header.outerHeight();
        var navbarMain_Height = header.find('.navbar-main').outerHeight();
        var win_width = $(window).width(); //浏览器当前窗口可视区域宽度
        var win_height = $(window).height(); //浏览器当前窗口可视区域高度
        var offset = header_Height;//跟随偏移量
        var offsetTop = header_Height - navbarMain_Height ;//微调偏移量
        var $body = $('body');


        /*搜索控制*/
        $('#search').find('.icon').click(function (event) {
            event.stopPropagation();
            var _me = $(this),
                topSearch = _me.siblings('.top-search');
            topSearch.toggleClass('on');
            topSearch.find('.btn-close').click(function () {
                _me.trigger('click');
            });
        });

        /*首页 骨架*/
        ;(function($){
            if($('#home').length){
                var homepage = new Swiper('#home', {
                    mode: 'vertical',
                    slidesPerView: 'auto',
                    cssWidthAndHeight:true,
                    pagination: '.home-pagination',
                    paginationClickable: true,
                    keyboardControl:true,
                    mousewheelControl:true,
                    paginationClickable :true,
                    speed: 700,
                    DOMAnimation:true,
                    watchActiveIndex : true,
                    offsetSlidesAfter : 2,
                    onSlideChangeStart: function (swiper) {
                        var me = this;

                        if (swiper.activeIndex > 0) {
                            header.addClass('xb-mod-header-down');
                        } else {
                            header.removeClass('xb-mod-header-down');
                        }

                        console.log(swiper.activeIndex )
                    }
                });

                var hotslide = new Swiper('#hot-slide',{
                    mode: 'horizontal',
                    slidesPerView: '1',
                });
            }

        })(jQuery);


        /*产品特点介绍 section1*/
        ;(function ($) {
            if ($('.product-features-detail').length) {

                var featuresDetails = new Swiper('.product-features-detail', {
                    mode: 'horizontal',
                    slidesPerView: '1',
                    calculateHeight: true
                });

                var features = new Swiper('.product-features', {
                    slidesPerView: 7,
                    spaceBetween: 0,
                    grabCursor: true,
                    pagination: '',
                    onFirstInit: function (swiper) {
                        var swiper = swiper,
                            swpProIndex = swiper.clickedSlideIndex;
                        // console.log(swiper);
                        $(swiper.slides[swiper.activeIndex]).addClass('swiper-slide-on');
                    },
                    onSlideClick: function (swiper) {
                        var swiper = swiper,
                            swpProIndex = swiper.clickedSlideIndex;
                        swiper.swipeTo(swpProIndex, 1000, false);
                        $(swiper.slides).removeClass('swiper-slide-on');
                        $(swiper.slides[swpProIndex]).addClass('swiper-slide-on');
                        featuresDetails.swipeTo(swpProIndex);
                    }
                });

                var swpIndex = 1;
                $('.features-button-next').click(function () {
                    // swpIndex++;
                    swpIndex++;
                    if (swpIndex >= features.slides.length) swpIndex = features.slides.length;
                    console.log(swpIndex);

                    features.swipeTo(swpIndex - 1, 1000, false);
                    $(features.slides).removeClass('swiper-slide-on');
                    $(features.slides[swpIndex - 1]).addClass('swiper-slide-on');
                    //关联详情
                    featuresDetails.swipeTo(swpIndex - 1, 1000, false);

                });

                $('.features-button-prev').click(function () {
                    // swpIndex--;
                    swpIndex--;
                    if (swpIndex <= 1) swpIndex = 1;
                    features.swipeTo(swpIndex - 1, 1000, false);
                    $(features.slides).removeClass('swiper-slide-on');
                    $(features.slides[swpIndex - 1]).addClass('swiper-slide-on');
                    //关联详情
                    featuresDetails.swipeTo(swpIndex - 1, 1000, false);
                    // console.log(swpIndex);
                    console.log(features)
                });
                //

                //关联控制器
                featuresDetails.addCallback('SlideChangeEnd', function (swiper) {
                    var me = swiper, activeIndex = me.activeIndex;
                    features.swipeTo(activeIndex, 1000, false);
                    // console.log(me);
                    $(features.slides).removeClass('swiper-slide-on');
                    $(features.slides[activeIndex]).addClass('swiper-slide-on');
                });
            }

        })(jQuery);



        /**
         *产品旋转木马
         */
        ;(function ($) {
            if($('#product-carousel').length){

            var productCarousel = $('#product-carousel'),
                title = $('#product-carousel-title'),
                partItem = productCarousel.find('.part-item'),
                tipsButton = productCarousel.find('.tips-button')
            ;
            productCarousel.Cloud9Carousel({
                buttonLeft: $("#buttons > .left"),
                buttonRight: $("#buttons > .right"),
                autoPlay: false,
                bringToFront: true,
                itemClass: 'product-item',
                frontItemClass: 'product-item-active',
                speed: 1,
                yRadius:100,
                // xRadius:600,
                onRendered: rendered,
                onAnimationFinished: function () {
                    //高亮
                    var Index = this.nearestIndex();
                    $(swiperProduct.slides).removeClass('swiper-slide-on');
                    $(swiperProduct.slides[Index]).addClass('swiper-slide-on');
                    swiperProduct.swipeTo(Index, 1000, false);

                },
                onLoaded:function(){
                    productCarousel.css( {'visibility':'visible','display':'none' } );
                    productCarousel.fadeIn(1500);
                    partItem.hover(function(){
                        var me = $(this),type = me.data('type') ;
                        me.addClass('partOn');
                        if(type == 'glass'){
                            me.stop().fadeOut(300) ;
                        }
                    },function(){
                        var me = $(this),type = me.data('type') ;
                        me.removeClass('partOn');
                        /*if(type == 'glass'){
                            me.stop().fadeIn() ;
                        }*/
                    });
                    /* partItem.on('mouseenter',function(e){
                         e.stopPropagation();
                         var me = $(this);
                         me.find('.bubble').fadeIn();
                         me.addClass('partOn');
                     });
                     partItem.on('mouseout',function(e){
                         e.stopPropagation();
                         var me = $(this);
                         me.find('.bubble').fadeOut();
                         me.removeClass('partOn');
                     });*/
                },

            });

            /*标题*/
            function rendered(carousel) {
                title.text(carousel.nearestItem().element.title)
                // Fade in based on proximity of the item
                var c = Math.cos((carousel.floatIndex() % 1) * 2 * Math.PI);
                title.css('opacity', 0.5 + (0.5 * c));
            }

            //产品控制器
            var swiperProduct = new Swiper('.product-container ', {
                mode: 'horizontal',
                slidesPerView: 6,
                spaceBetween: 0,
                grabCursor: true,
                slideToClickedSlide: true,

                calculateHeight:true,
                pagination: "",

                slideChange: function () {
                    var me = this;
                    var activeIndex = me.activeIndex;
                },
                onFirstInit: function (swiper) {
                    //Swiper初始化
                    $(swiper.slides[swiper.activeIndex]).addClass('swiper-slide-on');
                },
                onSlideClick: function (swiper) {
                    /*点击时*/
                    var swiper = swiper,
                        swpProIndex = swiper.clickedSlideIndex;
                    swiper.swipeTo(swpProIndex, 1000, false);

                    $(swiper.slides).removeClass('swiper-slide-on');
                    $(swiper.slides[swpProIndex]).addClass('swiper-slide-on');
                    /*关联旋转马*/
                    productCarousel.data("carousel").goTo(swpProIndex);
                    // console.log( productCarousel.data("carousel"));
                }
            });
            //基于swiper 通过绑定按钮事件让控制器左右滑动，兼顾响应式
            var swpProIndex = 0;
            //right
            $('.product-button-next').click(function () {
                // swpIndex++;
                swpProIndex++;
                if (swpProIndex >= swiperProduct.slides.length) swpProIndex = swiperProduct.slides.length - 1;
                // console.log(swpIndex);
                swiperProduct.swipeTo(swpProIndex, 1000, false);
                $(swiperProduct.slides).removeClass('swiper-slide-on');
                $(swiperProduct.slides[swpProIndex]).addClass('swiper-slide-on');
                //关联详情
                productCarousel.data("carousel").goTo(swpProIndex);

                // console.log(swpProIndex);
            });
            //left
            $('.product-button-prev').click(function () {
                // swpIndex--;
                swpProIndex--;
                if (swpProIndex <= 0) swpProIndex = 0;
                swiperProduct.swipeTo(swpProIndex, 1000, false);
                $(swiperProduct.slides).removeClass('swiper-slide-on');
                $(swiperProduct.slides[swpProIndex]).addClass('swiper-slide-on');
                //关联详情
                productCarousel.data("carousel").goTo(swpProIndex);

                // console.log(swpProIndex);
            })
        }
        })(jQuery);

        /**
         *内页开始
         */
        //内页左侧菜单
        ;(function () {
            var navTree = $('.nav-tree'),
                childrenNode = navTree.children()
            ;

            childrenNode.each(function (i) {
                /*item :li*/
                var item = $(this),
                    // subItem = item.children().children('li'),
                    nodeName = item.get(0).tagName,
                    subItem = item.children().children(nodeName);
                if (subItem.length > 0) item.addClass('has-list');

                item.find('>a').click(function (e) {
                    var me = $(this),
                        parentNode = me.parent();

                    if(subItem.is(":hidden")){
                        parentNode.siblings().removeClass('open');
                        parentNode.addClass('open');
                        parentNode.siblings().find('>ul').slideUp()
                        parentNode.find('>ul').slideDown();
                    }else {
                        parentNode.removeClass('open');
                        parentNode.siblings().removeClass('open');
                        parentNode.siblings().find('>ul').slideUp()
                        parentNode.find('>ul').slideUp();
                    }

                    if (subItem.length > 0){
                        return false;
                    }

                });
                /*
                console.log(this);
                 console.log(item);
                 console.log(item.get(0).tagName);
                 */
            });

        })();

        //产品中心scrollbar

        /**
         * 产品选型筛选
         */

        $('#btn-switch').on('click', function () {
            $(this).toggleClass('on');
            $('#filter-body').slideToggle();
        });



        // tabs 首页
        /*
        $("#nav-case-tabsIndex").tabs(".nav-case-tabsContent > div",{
        event:'mouseover',
        tab:'div',
        tabs:'.item',
        effect: 'default',
        current:'active',
        fadeInSpeed:600}
        );
        */

        // 让页面滚动更有趣
        (function () {
            /*    window.sr = ScrollReveal({
                reset: false,
                viewFactor : 0.15,
                duration   : 600,
                distance   : "10px",
                scale      : 0,
                    opacity: 0,
                    easing: 'cubic-bezier(0.6, 0.2, 0.1, 1)',
                    mobile: true,
                    useDelay: 'always'
              });
              sr.reveal('.xb-module');
              sr.reveal('.list-item');
              sr.reveal('.footer');*/
            // sr.reveal('.b1-ele-5', { container: '#full-slide', origin:"left",delay:1500},50);
        })();

    });

})(jQuery);

































